package com.example.hp.myapplication.activity;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.hp.myapplication.R;
import com.example.hp.myapplication.adapter.MyPadgerAdapet;

import java.util.ArrayList;
import java.util.List;

public class GuideActivity extends AppCompatActivity {
    private List<View> viewList;
    ViewPager viewPager;
    int [] pics={R.drawable.guide1,R.drawable.guide2,R.drawable.guide3,R.drawable.guide4};
    LinearLayout pointLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        initView();
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                for (int i=0;i<pointLayout.getChildCount();i++)
                {
                    ImageView imageView= (ImageView) pointLayout.getChildAt(i);
                    if(position==i)
                    {
                        imageView.setImageResource(R.drawable.point_select);
                    }
                    else
                    {
                        imageView.setImageResource(R.drawable.point_normal);
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }
    private  void  initView()
    {
        viewList=new ArrayList<View>();
        for (int i=0;i<pics.length;i++)
        {
            View view= LayoutInflater.from(this).inflate(R.layout.guide_item,null);
            view.setBackgroundResource(pics[i]);
            viewList.add(view);
        }
        viewPager= (ViewPager) findViewById(R.id.viewPager);
        viewPager.setAdapter(new MyPadgerAdapet(viewList,this));
        pointLayout= (LinearLayout) findViewById(R.id.pointLayout);
        for (int i=0;i<pics.length;i++)
        {
            ImageView imgView=new ImageView(this);
            if(i==0)
            {
                imgView.setImageResource(R.drawable.point_select);
            }
            else
            {
                imgView.setImageResource(R.drawable.point_normal);
            }
            LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                                                                            ViewGroup.LayoutParams.WRAP_CONTENT);
            imgView.setLayoutParams(params);
            imgView.setPadding(5,0,5,0);
            pointLayout.addView(imgView);
        }

    }
}
